package com.hf.lookatme.zview.adapters;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.hf.lookatme.utils.ImageLoaderConfigUtils;
import com.hf.lookatme.zbean.AdvertisementData;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by JoeShiguang on 2015/5/28.
 */
public class Adapter_ViewPager_Adversement extends PagerAdapter {

  private Context context;

  private List<AdvertisementData> list_data;

  private ImageLoader imageLoader;

  public Adapter_ViewPager_Adversement(Context context, List<AdvertisementData> list_data) {
    this.context = context;
    this.list_data = list_data;
    this.imageLoader = ImageLoaderConfigUtils.instanceImageLoader(context);
  }


  @Override
  public int getCount() {
    if (list_data != null) {
      return list_data.size();
    }
    return 0;
  }

  @Override
  public boolean isViewFromObject(View view, Object object) {
    return view == object;
  }

  @Override
  public void destroyItem(ViewGroup container, int position, Object object) {

    container.removeView((View) object);
  }

  @Override
  public Object instantiateItem(ViewGroup container, int position) {

    ImageView imageView = new ImageView(context);
    imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
    imageLoader.displayImage(list_data.get(position).getImgUrl(), imageView);
    container.addView(imageView);
    return imageView;
  }
}
